﻿
using SvCore.CallOut;
using UtilLib;

namespace ServerBase.Config;

// 全局配置
public class GlobalConfigExt
{
    public int GlobalId;
    public ConfigGlobal SettBase;
    public string Value;
    public bool ValueBool;
    public int ValueInt;
    public long ValueLong;
    public float ValueFloat;
    public List<string> ValueListString;
    public List<int> ValueListInt;
    public List<float> ValueListfloat;
    public List<List<int>> ValueListListInt;
    public GlobalConfigExt(ConfigGlobal v)
    {
        GlobalId = v.GlobalId;
        SettBase = v;
        Value = v.Value;
        ValueBool = Value.ToBool();
        ValueInt = Value.ToInt();
        ValueLong = Value.ToLong();
        ValueFloat = Value.ToFloat();
        ValueListString = Value.ToListString(Conf.ConfListSeparator, true);
        ValueListInt = Value.ToListInt(Conf.ConfListSeparator);
        ValueListfloat = Value.ToListFloat(Conf.ConfListSeparator);
        ValueListListInt = Value.ToListListInt(Conf.ConfDictionarySeparator1, Conf.ConfDictionarySeparator2);
    }
}
// 房间
public class ConfigRoomExt
{
    public long Id;
    public ConfigRoom SettBase;
    public Dictionary<int, int> DictItems = new Dictionary<int, int>();
    public Dictionary<int, int> DictEquips = new Dictionary<int, int>();
    public Dictionary<int, int> DictNpcs = new Dictionary<int, int>();
    public List<EInitType> Inits = new List<EInitType>(); // 触发事件列表
    public List<EActType> Acts = new List<EActType>(); // 提供事件列表
    public List<EResourceType> Resources = new List<EResourceType>(); // 提供资源列表
    public ConfigRoomExt(ConfigRoom v)
    {
        Id = v.Id;
        SettBase = v;
        foreach (var item in v.Items)
        {
            if (item.Count < 2)
            {
                continue;
            }
            DictItems.TryGetValue(item[0], out var oldcount);
            DictItems[item[0]] = oldcount + item[1];
        }
        foreach (var item in v.Equips)
        {
            DictEquips.TryGetValue(item, out var oldcount);
            DictEquips[item] = oldcount + 1;
        }
        foreach (var item in v.Npcs)
        {
            DictNpcs.TryGetValue(item, out var oldcount);
            DictNpcs[item] = oldcount + 1;
        }
        foreach (var item in SettBase.Inits)
        {
            if (item.IsNullOrEmpty())
            {
                continue;
            }
            if (!item.TryParseEnum(out EInitType data))
            {
                loger.Error($"ConfigRoom 触发事件列表 枚举错误 {item}");
                continue;
            }
            Inits.Add(data);
        }
        foreach (var item in SettBase.Acts)
        {
            if (item.IsNullOrEmpty())
            {
                continue;
            }
            if (!item.TryParseEnum(out EActType data))
            {
                loger.Error($"ConfigRoom 提供事件列表 枚举错误 {item}");
                continue;
            }
            Acts.Add(data);
        }
        foreach (var item in SettBase.Resources)
        {
            if (item.IsNullOrEmpty())
            {
                continue;
            }
            if (!item.TryParseEnum(out EResourceType data))
            {
                loger.Error($"ConfigRoom 提供资源列表 枚举错误 {item}");
                continue;
            }
            Resources.Add(data);
        }
    }
}
// 道具
public class ConfigItemExt
{
    public int Id;
    public ConfigItem SettBase;
    public List<ECalloutType> Callouts = new(); //延迟效果
    public ConfigItemExt(ConfigItem v)
    {
        Id = v.Id;
        SettBase = v;
        foreach (var item in SettBase.Callouts)
        {
            if (item.IsNullOrEmpty())
            {
                continue;
            }
            if (!item.TryParseEnum(out ECalloutType data))
            {
                loger.Error($"ConfigItem 延迟效果 枚举错误 {item}");
                continue;
            }
            Callouts.Add(data);
        }
    }
}
// NPC
public class ConfigNpcExt
{
    public int Id;
    public ConfigNpc SettBase;
    public List<EInitType> Inits = new(); // 触发事件列表
    public ConfigNpcExt(ConfigNpc v)
    {
        Id = v.Id;
        SettBase = v;
        foreach (var item in SettBase.Inits)
        {
            if (item.IsNullOrEmpty())
            {
                continue;
            }
            if (!item.TryParseEnum(out EInitType data))
            {
                loger.Error($"ConfigItem 触发事件 枚举错误 {item}");
                continue;
            }
            Inits.Add(data);
        }
    }
}
// 武器种类
public class ConfigWeaponTypeExt
{
    public string Id;
    public ConfigWeaponType SettBase;
    public List<ConfigCbtAction> ListActions = new List<ConfigCbtAction>();
    public EUsageType UsageType = EUsageType.扑击格斗;
    public ConfigWeaponTypeExt(ConfigWeaponType v)
    {
        Id = v.Id;
        SettBase = v;
        UsageType = (EUsageType)v.UsageType;
        foreach (var item in v.Verbs)
        {
            if (item.IsNullOrEmpty())
            {
                continue;
            }
            ListActions.Add(Conf.ConfCbtAction[item]);
        }
    }
}
// 种族
public class ConfigRaceExt
{
    public int Id;
    public ConfigRace SettBase;
    public List<ConfigCbtAction> ListActions = new List<ConfigCbtAction>();
    public ConfigRaceExt(ConfigRace v)
    {
        Id = v.Id;
        SettBase = v;
        foreach (var item in v.Actions)
        {
            if (item.IsNullOrEmpty())
            {
                continue;
            }
            ListActions.Add(Conf.ConfCbtAction[item]);
        }
    }
}

